package level

import (
	"encoding/json"
	"fmt"
	"kop/modules/configuration/client"
	"kop/util/log"
)

func init() {

	if err := json.Unmarshal(client.Load("PlayerPeerage"), &Configs); err != nil {
		panic(err)
	}

	log.Info("Load PlayerPeerage.json success.")

}

// 爵位配置
type (
	Conf struct {
		Level         int32   `json:"ID"` // 爵位ID
		Name          string  // 爵位名称
		Quality       int32   // 爵位品质
		MoneyRateAll  float64 // 所有银币收益加成比例
		SailorMax     int32   // 每艘海盗船招募水手上限
		OfflineTime   int64   // 离线收益累计时间(分)
		AwardDiamond  int32   // 爵位钻石奖励
		NeedRenown    int32   // 晋升需要海盗声望
		NeedIncome    int64   // 晋升需要海盗船收益
		StandardGold  int32
		StandardINT   int32 // 船长标准智力
		StandardCOR   int32 // 船长标准勇气
		StandardCHR   int32 // 船长标准魅力
		PositionCount int32 // 上阵数量
		EventCount    int   // 事件数量
		AwardID       int32
		KidMax        int32 // 调戏次数
	}
)

var (
	Configs = map[int32]Conf{}
)

func GetByRoleLevel(level int32) (Conf, error) {

	var conf, ok = Configs[level]
	if ok {
		return conf, nil
	}

	return Conf{}, fmt.Errorf("peerage not found [%d]", level)
}

func GetMaxKid(lv int32) int32 {

	var conf, ok = Configs[lv]
	if !ok {
		panic(fmt.Errorf("peerage not found [%d]", lv))
	}

	return conf.KidMax
}

func GetStandardGold(lv int32) int32 {

	var conf, ok = Configs[lv]
	if !ok {
		panic(fmt.Errorf("peerage not found [%d]", lv))
	}

	return conf.StandardGold
}
